﻿using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Text;

namespace amuudp.package
{
    public class ImagePackage
    {
        public int Index { get; private set; }
        public Bitmap BitMap { get; private set; }

        public ImagePackage(Package package)
        {
            if (!package.Complete)
            {
                throw new Exception("数据包接收不完整");
            }

            if (package.Type != PackageType.Image)
            {
                throw new Exception("数据包不是图片类型");
            }

            this.Index = UdpCommon.ByteCopyToInt(package.Bytes, 16);
            Stream stream = new MemoryStream(package.Bytes, 24, package.Bytes.Length - 24);
            this.BitMap = new Bitmap(stream);
        }
    }

}
